<?php
    header('Content-type:text/json');
    require "../../connection.php";
    $data = NULl;
    try{
            $name =$_POST['name'];
            $zhname = $_POST['zhname'];
            $sqls = 'select * from category where en_name = "'.$name.'" and zh_name = "'.$zhname.'"';
            $res = $conn->doSql($sqls);
            if(!$res){
                $arr = array("en_name"=>$name,"zh_name"=>$zhname);
                $sql = "insert into category (en_name,zh_name) value('".$name."','".$zhname."')";
                $result = $conn->doSql($sql);
                if($result){
                    $msg = "插入成功";
                    $data = $conn->doSql("select * from category");
                }else{
                    $msg = "插入失败";
                }
            }else{
                $msg = "数据已存在，创建失败";
            }
            $data = array("status"=>"1","msg"=>$msg,"data"=>$data);
            echo json_encode($data);
    }catch(Exception $e){
       echo  json_encode($e->getMessage());
    }
?>